package com.qili.service.supplier.impl;

import com.qili.base.mapper.BaseMapper;
import com.qili.base.service.impl.BaseServiceImpl;
import com.qili.entity.supplier.ProjectPlace;
import com.qili.entity.supplier.ProjectPlaceChange;
import com.qili.entity.supplier.SupplierProject;
import com.qili.entity.supplier.SupplierProjectChange;
import com.qili.entity.supplier.dto.ProjectPlaceDTO;
import com.qili.entity.supplier.dto.SupplierProjectChangeDTO;
import com.qili.entity.supplier.dto.SupplierProjectDTO;
import com.qili.mapper.supplier.SupplierProjectChangeMapper;
import com.qili.mapper.supplier.SupplierProjectMapper;
import com.qili.service.supplier.ProjectPlaceChangeService;
import com.qili.service.supplier.ProjectPlaceService;
import com.qili.service.supplier.SupplierProjectManagerChangeService;
import com.qili.service.supplier.SupplierProjectManagerService;
import com.qili.util.BeanUtil;
import com.qili.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhaoyongke
 * @date 2021/3/29
 * @description
 */
@Service
public class SupplierProjectManagerChangeServiceImpl extends BaseServiceImpl<SupplierProjectChange,String> implements SupplierProjectManagerChangeService {

    @Autowired
    private SupplierProjectChangeMapper supplierProjectChangeMapper;
    @Autowired
    private ProjectPlaceChangeService projectPlaceChangeService;


    @Override
    public BaseMapper<SupplierProjectChange, String> getMappser() {
        return supplierProjectChangeMapper;
    }

    @Autowired
    public List<SupplierProjectChangeDTO> selectProject(SupplierProjectChangeDTO dto){
        return    supplierProjectChangeMapper.selectProject(dto);
    };
    @Override
    public SupplierProjectChangeDTO getChangeProject(SupplierProjectDTO  dto){
        SupplierProjectChangeDTO  changeDTO=new SupplierProjectChangeDTO();
        changeDTO.setSupProjectId(dto.getSupProjectId());
        List<SupplierProjectChangeDTO> list=supplierProjectChangeMapper.selectProject(changeDTO);
        if(list!=null ){
            if(list.size()>0){
                changeDTO= list.get(0);
            }

        }

        return   changeDTO;
    }

    /**
     * @Author:zhaoyongke
     * @Description:
     * @param supplierProjectDTO
     * @param project
     * @Date:13:32 2021/3/29
     */
    @Override
    public void addPersonPalceChange(SupplierProjectChangeDTO supplierProjectDTO, SupplierProject project )  throws  Exception {
        List<ProjectPlaceDTO> personPlacedtos = supplierProjectDTO.getPersonPlacedtos();
        for (int i = 0; i <personPlacedtos.size() ; i++) {
            ProjectPlaceDTO dto= personPlacedtos.get(i);
            if(StringUtil.isNotBlank(dto.getProvince())){
                ProjectPlaceChange  place=new ProjectPlaceChange();
                BeanUtil.copyNotNullBean(dto, place);
                place.setType("002");// 001 实施地点 002 人员要求地点
                place.setSupProjectId(project.getSupProjectId());
                place.setSupProjectChangeId(supplierProjectDTO.getSupProjectChangeId());
                projectPlaceChangeService.insertSelective(place);
            }

        }
    }
   /**
   * @Author:zhaoyongke
   * @Description:
   * @param supplierProjectDTO
    * @param project
   * @Date:17:57 2021/3/29
   */
    @Override
    public void addPalceChange(SupplierProjectChangeDTO supplierProjectDTO, SupplierProject project )  throws  Exception {
        List<ProjectPlaceDTO> projectPlacedtos = supplierProjectDTO.getProjectPlacedtos();
        for (int i = 0; i <projectPlacedtos.size() ; i++) {
            ProjectPlaceDTO dto= projectPlacedtos.get(i);
            ProjectPlaceChange place=new ProjectPlaceChange();
            BeanUtil.copyNotNullBean(dto, place);
            place.setType("001");// 001 实施地点 002 人员要求地点
            place.setSupProjectId(project.getSupProjectId());
            place.setSupProjectChangeId(supplierProjectDTO.getSupProjectChangeId());
            projectPlaceChangeService.insertSelective(place);
        }
    }


}
